//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by mac on 15/12/13.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    //必选属性
   let mainTabbar = MainTabbar()
    
    @objc private func composeBtnDidClick() {
        print(__FUNCTION__)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
       // print(tabBar.classForCoder)
      //  let mainTabbar = MainTabbar()
          mainTabbar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        //tabBar 是只读属性 不能够直接进行设置  可以使用  KVC 在运行时 间接赋值 (改变身份)
        setValue(mainTabbar, forKey: "TabBar")
        //print(tabBar.classForCoder)
        
    
        view.backgroundColor = UIColor(white: 0.934, alpha: 1)
        
        addChildViewControllers()

    }
    

    
    
    //private表示只能在本类中访问
   private func addChildViewControllers(){
    addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
    addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
    addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
   addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")

    }
    private func addChildViewController(vc:UIViewController ,title:String,imageName:String){
       self.tabBar.tintColor = UIColor.orangeColor()
        
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        self.addChildViewController(nav)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
